home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Leser 15
/
Amiga Plus Leser CD 15.iso
/
Tools
/
Development
/
PluginSRC_EvenMore
/
guide2text3.e
< prev
next >
Wrap
Text File
|
2002-03-12
|
11KB
|
352 lines
/*
Guide 2 Text
EvenMore FileIO plugin
Author: Chris Perver
Copyright (c) 2001
*/
OPT REG=5
LIBRARY 'guide2text.plugin',1,1,'Guide2Text 1.16' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
MODULE 'tools/ctype', '*epo'
DEF mem2, len2, numchars =0
PROC em_isdatatype(memadr)
DEF tstr[10]:STRING
IF memadr[0] = "@"
StrCopy(tstr, memadr + 1, 10)
LowerStr(tstr)
IF InStr(tstr,'database') = 0 THEN RETURN TRUE
ENDIF
ENDPROC FALSE
PROC em_parsedata(epo:PTR TO em_pluginobj)->memadr, lenadr)
DEF memadr:PTR TO CHAR, lenadr:PTR TO CHAR
DEF count = 0, count2 = 0, newcount = 0, newcount2 = 0, tempstr[10]:STRING
DEF foundag = FALSE, printwordnum = 0, ww = FALSE, wordwrap = 80
DEF oldpos:PTR TO CHAR, oldcount, oldcc
memadr := epo.buffer
lenadr := epo.length
-> Allocate memory for file
-> IF (mem2 := New(lenadr + 1)) = NIL THEN RETURN -1
-> mem2[lenadr + 1] := "\n" -> Put safety LF at the end of mem
mem2 := memadr
WHILE (count < lenadr) -> while we are not at the end of the file
IF memadr[count] = "@" -> if command then
-> Check for keywords
StrCopy(tempstr, memadr + count + 1, 10) -> Find out what command is
LowerStr(tempstr)
newcount := 0
newcount2 := 0
printwordnum := -1
foundag := TRUE
IF tempstr[0] = "{" -> Check all keywords
printwordnum := 0
ELSEIF InStr(tempstr,'database') = 0
ELSEIF InStr(tempstr,'node') = 0
ELSEIF InStr(tempstr,'endnode') = 0
ELSEIF InStr(tempstr,'title') = 0
ELSEIF InStr(tempstr,'index') = 0
ELSEIF InStr(tempstr,'author') = 0
ELSEIF InStr(tempstr,'wordwrap') = 0
ww := TRUE
ELSEIF InStr(tempstr,'master') = 0
ELSEIF InStr(tempstr,'width') = 0
ELSEIF InStr(tempstr,'prev') = 0
ELSEIF InStr(tempstr,'next') = 0
ELSEIF InStr(tempstr,'toc') = 0
ELSEIF InStr(tempstr,'$ver') = 0
ELSEIF InStr(tempstr,'(c)') = 0
ELSEIF InStr(tempstr,'rem') = 0
ELSEIF InStr(tempstr,'font') = 0
ELSEIF InStr(tempstr,'smartwrap') = 0
ww := TRUE
ELSEIF InStr(tempstr,'language') = 0
ELSE
foundag := FALSE
newcount := 1
newcount2 := 1
mem2[count2] := memadr[count] -> copy the char
ENDIF
IF foundag
oldpos := mem2 + count2
newcount, newcount2 := skipcomm(memadr + count, lenadr - count, oldpos, printwordnum)
ENDIF
-> numchars := numchars + newcount2
count := count + newcount
count2 := count2 + newcount2
ELSE
-> Skip backslash if doubled
IF memadr[count] = $5C
IF memadr[count + 1] = $5C THEN INC count
ENDIF
mem2[count2++] := memadr[count++] -> copy the char
-> WORDWRAP IF NECESSARY
-> WORDWRAP
IF ww
IF numchars >= wordwrap
-> Find last space
IF isspace(mem2[count2]) = TRUE
mem2[count2++] := "\n"
numchars := 0
ELSE
oldcount := count2
oldcc := numchars
WHILE isspace(mem2[count2]) = FALSE
mem2[count2 + 1] := mem2[count2]
DEC count2
DEC numchars
ENDWHILE
INC count2
mem2[count2] := "\n"
numchars := oldcc - numchars ->currchar
count2 := oldcount + 1
ENDIF
ENDIF
ENDIF
/* IF ww = TRUE
IF memadr[count] = "\n"
numchars := 0
ELSE
IF numchars >= 80
-> Find last space
WHILE isspace(memadr[count]) = FALSE
DEC count
DEC count2
ENDWHILE
IF memadr[count] = "["
IF memadr[count - 1] = "\e"
count := count - 2
ENDIF
ENDIF
mem2[count2++] := "\n"
IF memadr[count] = " " THEN INC count
numchars := 0
ELSE
numchars := numchars +1
ENDIF
ENDIF
ENDIF
*/
ENDIF
ENDWHILE
mem2[count2] := "\n"
-> IF memadr
-> Dispose(memadr); memadr := NIL
-> ENDIF
ENDPROC mem2, count2
-><
->> skipcomm(fmem:PTR TO CHAR,len, newmem, printword = 0)
PROC skipcomm(fmem:PTR TO CHAR,len, newmem, printword = 0)
DEF count = 0, count2 = 0, iscomm = FALSE, notdone = TRUE, quotes = FALSE, wordsdone = 0, spaces = FALSE
DEF tempstr[10]:STRING
WHILE notdone
IF fmem[count]=" " -> If space
IF spaces -> If we are skipping them
INC count -> Skip space
ELSE -> If this is a new space
IF quotes -> If we are not in a quote
IF wordsdone = printword
newmem[count2] := fmem[count] -> Copy space
INC count2
INC numchars
ENDIF
INC count
ELSE
spaces := TRUE -> We are now skipping spaces
INC wordsdone -> We have counted a new word
INC count -> Skip space
ENDIF
ENDIF
ELSEIF fmem[count]=$22 -> If "
newmem[count2++] := "\e" ->
newmem[count2++] := "["
IF quotes -> If we are in a quote
quotes := FALSE -> End this quote
INC count -> Skip "
newmem[count2++] := "0"
ELSE -> If we aren't in a quote
quotes := TRUE -> We are in a quote
INC count -> Skip
newmem[count2++] := "2"
ENDIF
newmem[count2++] := "m"
ELSEIF fmem[count]="{" -> If {
IF quotes -> If we are in a quote
IF wordsdone = printword -> If we are at the word to copy
newmem[count2] := fmem[count] -> Copy {
INC count2
ENDIF
INC count -> Skip {
ELSE -> If we aren't in a quote
iscomm := TRUE
SELECT 256 OF fmem[count + 1]
CASE "u","U" -> If found U command
newmem[count2++] := "\e"
newmem[count2++] := "["
IF fmem[count+2] = "}" -> Its underscore
newmem[count2++] := "4"
ELSE
newmem[count2++] := "2"
SELECT 256 OF fmem[count+2] -> Its undoing one of these styles
CASE "u","U"; newmem[count2++] := "4"
CASE "b","B"; newmem[count2++] := "1"
CASE "i","I"; newmem[count2++] := "3"
ENDSELECT
ENDIF
newmem[count2++] := "m"
CASE "i","I"
IF fmem[count+2] = "}"
newmem[count2++] := "\e"
newmem[count2++] := "["
newmem[count2++] := "3"
newmem[count2++] := "m"
ENDIF
CASE "f","F" -> FG pen
IF fmem[count+2] = ("g" OR "G")
count := count + 4 -> Skip char
StrCopy(tempstr, fmem + count, 10)
LowerStr(tempstr)
newmem[count2++] := "\e"
newmem[count2++] := "["
newmem[count2++] := "3"
IF InStr(tempstr, 'filltext') = 0; newmem[count2++] := "1"
ELSEIF InStr(tempstr, 'fill') = 0; newmem[count2++] := "3"
ELSEIF InStr(tempstr, 'text') = 0; newmem[count2++] := "1"
ELSEIF InStr(tempstr, 'highlight') = 0; newmem[count2++] := "2"
ELSEIF InStr(tempstr, 'back') = 0; newmem[count2++] := "0"
ELSEIF InStr(tempstr, 'shine') = 0; newmem[count2++] := "2"
ENDIF
newmem[count2++] := "m"
ENDIF
CASE "b","B"
IF fmem[count+2] = "}"
newmem[count2++] := "\e"
newmem[count2++] := "["
newmem[count2++] := "1"
newmem[count2++] := "m"
ELSEIF fmem[count+2] = ("g" OR "G") -> BG pen change
count := count + 4 -> Skip char
StrCopy(tempstr, fmem + count, 10)
LowerStr(tempstr)
newmem[count2++] := "\e"
newmem[count2++] := "["
newmem[count2++] := "4"
IF InStr(tempstr, 'filltext') = 0; newmem[count2++] := "1"
ELSEIF InStr(tempstr, 'fill') = 0; newmem[count2++] := "3"
ELSEIF InStr(tempstr, 'text') = 0; newmem[count2++] := "1"
ELSEIF InStr(tempstr, 'highlight') = 0; newmem[count2++] := "2"
ELSEIF InStr(tempstr, 'back') = 0; newmem[count2++] := "0"
ELSEIF InStr(tempstr, 'shine') = 0; newmem[count2++] := "2"
ENDIF
newmem[count2++] := "m"
ENDIF
ENDSELECT
INC count -> Skip {
ENDIF
ELSEIF fmem[count]="}" -> If }
IF quotes -> If we are in a quote
IF wordsdone = printword
newmem[count2] := fmem[count] -> Copy }
INC count2
ENDIF
INC count
ELSE -> If we aren't in a quote
IF iscomm -> If we are in a command
notdone := FALSE -> End of command
INC count -> Skip }
ENDIF
ENDIF
ELSEIF fmem[count]="\n" -> If EOL
notdone := FALSE -> End
numchars := 0
ELSE -> If any other text
IF quotes -> If we are in a quote
IF wordsdone =printword
newmem[count2] := fmem[count] -> Copy text
INC count2
INC numchars
ENDIF
INC count
ELSE -> If we aren't in a quote
IF spaces -> If we are counting spaces
spaces := FALSE -> Stop counting spaces
INC count -> Skip text
ELSE -> If not counting spaces
INC count -> Skip text
ENDIF
ENDIF
ENDIF
ENDWHILE
ENDPROC count, count2
-><
-> *** STANDARD PROCS FOR PLUGINS
PROC em_main(epo:PTR TO em_pluginobj)
mem2, len2 := em_parsedata(epo) ->epo.buffer, epo.length)
epo.buffer := mem2
epo.length := len2
RETURN TRUE
ENDPROC
PROC em_begin(epo:PTR TO em_pluginobj)
IF em_isdatatype(epo.buffer) = TRUE
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC em_end() IS EMPTY
PROC em_info() IS 'Guide2Text 1.16'
PROC em_pluginid() IS "FILE"
PROC em_format() IS 'AmigaGuide'
PROC main() IS EMPTY